package com.pro.controller;

import com.pro.pojo.JsComment;
import com.pro.pojo.JsGoodsComment;
import com.pro.pojo.JsProduct;
import com.pro.pojo.JsonData;
import com.pro.service.JsCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author cyj
 * @date 2002.3.11$ 15.38$
 * @content :
 */
@RestController
@RequestMapping("/Comments")
public class JsCommentController {
    @Autowired
    private JsCommentService service;
    /**
     * @author cyj
     * @date 2002.3.14$ 14.36$    3.21  15.55··
     * @content :获取商品评论
     */
    @RequestMapping("/selectGoodComment")
    public JsonData selectGoodComment(Integer type,String status,Integer page,Integer limit){
        if(status==null){
            status="1";
        }
        List<JsComment> goodsComment = service.selectGoodComment(type,status,page,limit);
        Integer count = service.GoodCommentCount(type,status);
        return goodsComment!=null?JsonData.buildSuccess(goodsComment,count):JsonData.buildError("暂无评论");
    }

    /**
     * @author cyj
     * @date 2002.3.14$ 14.36$
     * @content :获取商品评论
     */
    @RequestMapping("/GoodCommentCount")
    public JsonData GoodCommentCount(String status,Integer type){
        Integer count = service.GoodCommentCount(type,status);
        return count!=null? JsonData.buildSuccess(count): JsonData.buildError("服务器错误");
    }

    @RequestMapping("/getGoodsNumber")
    public JsonData selectGoodsNumber(String status, Integer type,String commentDate){
        //status = status!=null&&!status.equals("")?"%"+status+"%":"%%";
        Integer count = service.GoodCommentCount(type,status);
        return count!=null? JsonData.buildSuccess(count): JsonData.buildError("服务端错误");
    }
    /**
     * @author cyj
     * @date 2022.3.25$ 11.38$
     * @content : 后台人员评论计数
     */
    @RequestMapping("/afterGoodCommentCount")
    public JsonData afterGoodCommentCount(String status,Integer type){
        Integer count = service.afterGoodCommentCount(type,status);
        return count!=null? JsonData.buildSuccess(count): JsonData.buildError("服务器错误");
    }
    /**
     * @author cyj
     * @date 2022.3.25$ 13.31$
     * @content : 获取后台人员的评论
     */
    @RequestMapping("/selectAfterGoodComment")
    public JsonData selectAfterGoodComment(Integer type,String status,Integer page,Integer limit){
        if(status==null){
            status="1";
        }
        List<JsComment> goodsComment = service.selectAfterGoodComment(type,status,page,limit);
        Integer count = service.afterGoodCommentCount(type,status);
        return goodsComment!=null?JsonData.buildSuccess(goodsComment,count):JsonData.buildError("暂无评论");
    }
    /**
     * @author cyj
     * @date 2022.3.25$ 13.57$
     * @content : 获取评论的计数
     */
    @RequestMapping("/countGoodComment")
    public JsonData countGoodComment(String userType,String commentDate){
        System.err.println(commentDate);
        Integer history = service.countComm(userType,null);
        Integer historyPeo = service.countPeo(userType,null).size();
        Integer today = service.countComm(userType,commentDate);
        Integer todayPeo = service.countPeo(userType,commentDate).size();
        List list = new ArrayList();
        list.add(history);
        list.add(historyPeo);
        list.add(today);
        list.add(todayPeo);
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务器错误");
    }

    /**
     * @author cyj
     * @date 2022.3.25$ 16.11$
     * @content : 获取后台人员的评论
     */
    @RequestMapping("/getOnlyComment")
    public JsonData getOnlyComment(Integer id){
        JsProduct jsComment = service.getOnlyComment(id);
        System.err.println(jsComment);
        return jsComment!=null?JsonData.buildSuccess(jsComment):JsonData.buildError("服务器错误");
    }
    /**
     * @author cyj
     * @date 2022.3.25$ 16.22$
     * @content : 拦截一条评论
     */
    @RequestMapping("/interceptComment")
    public JsonData interceptComment(Integer id,String status){
        Boolean flag = service.interceptComment(id,status);
        return flag!=null?JsonData.buildSuccess(flag):JsonData.buildError("服务器错误");
    }
    /**
     * @author cyj
     * @date 2022.3.25$ 16.36$
     * @content : 删除一条评论
     */
    @RequestMapping("/delComment")
    public JsonData delComment(Integer id){
        Boolean flag = service.delComment(id);
        return flag!=null?JsonData.buildSuccess(flag):JsonData.buildError("服务器错误");
    }
    /**
     * @author cyj
     * @date 2022.3.25$ 17.01$
     * @content : 获取一条后台评论详细信息
     */
    @RequestMapping("/getOnlyAfterComment")
    public JsonData getOnlyAfterComment(Integer id){
        JsProduct flag = service.getOnlyAfterComment(id);
        return flag!=null?JsonData.buildSuccess(flag):JsonData.buildError("服务器错误");
    }
}
